﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Operations;
using ITAP.ShprossesBuilder.Modelling.Components;

namespace ITAP.ShprossesBuilder.Manipulation
{
    public class CommandOperation : SerializedUndoRedo, IModelComponentCommand
    {
        IOperation operation;
        public CommandOperation(ModelControl modelControl, IOperation operation)
        {
            this.modelControl = modelControl;
            this.operation = operation;
        }

        #region ICommand Members

        public void StartExecute()
        {
            if(operation.CanUndo)
                this.undoModelContainer = (ModelContainer)this.modelControl.ModelContainer.Clone();

            this.operation.Execute(this.modelControl);
        }

        public void Execute()
        {
        }

        public void EndExecute()
        {
        }

        public bool IsNeedModelUpdate
        {
            get { return true; }
        }

        public string Name
        {
            get { return operation.Name; }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            CommandOperation clone = new CommandOperation(this.modelControl, this.operation);

            if (this.undoModelContainer != null)
                clone.undoModelContainer = (ModelContainer)this.undoModelContainer.Clone();
            if (this.redoModelContainer != null)
                clone.redoModelContainer = (ModelContainer)this.redoModelContainer.Clone();

            return clone;
        }

        #endregion

        public override bool CanUndo
        {
            get
            {
                return operation.CanUndo;
            }
        }

        #region IModelComponentCommand Members

        public List<IComponent> ComponentsForProcessing
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region IModelControlCommand Members

        private MouseManagerEvent mouseEvent;
        public MouseManagerEvent MouseEvent
        {
            get
            {
                return mouseEvent;
            }
            set
            {
                mouseEvent = value;
            }
        }

        public ModelControl ModelControl
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private System.Drawing.Point mouseDownPoint;
        public System.Drawing.Point MouseDownPoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        private System.Drawing.Point mouseUpPoint;
        public System.Drawing.Point MouseUpPoint
        {
            get
            {
                return mouseUpPoint;
            }
            set
            {
                mouseUpPoint = value;
            }
        }

        private System.Drawing.Point mouseMovePoint;
        public System.Drawing.Point MouseMovePoint
        {
            get
            {
                return mouseMovePoint;
            }
            set
            {
                mouseMovePoint = value;
            }
        }

        public bool ExecuteImmediately
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        public override string ToString()
        {
            return this.Name;
        }

        #region ICommand Members


        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        #endregion

        #region ICommand Members


        public bool IsNeedVisitorsUpdate
        {
            get { return true; }
        }

        #endregion
    }
}
